package com.bolt.support.query.calculator.domain;

import com.bolt.common.utils.StrUtil;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;

public class UnpivotModel implements Serializable {

    private Map<String, String> transformColumns;

    private String[] columnsLabels;


    public String[] getColumnsLabels() {
        return columnsLabels;
    }

    public Map<String, String> getTransformColumns() {
        return transformColumns;
    }

    public UnpivotModel setTransformColumns(String... columnsToRows) {
        transformColumns = new LinkedHashMap<>();
        for (String column : columnsToRows) {
            String[] columns = StrUtil.split(column,",");
            for (String col : columns) {
                String[] columnValue = StrUtil.split(col.replaceFirst("\\：", ":"), ":");
                if (columnValue.length == 2) {
                    transformColumns.put(columnValue[0], columnValue[1]);
                }
            }
        }
        return this;
    }


    public UnpivotModel setColumnsLabels(String... newColumnsLabels) {
        if (newColumnsLabels != null && newColumnsLabels.length > 0) {
            if (newColumnsLabels.length > 1) {
                this.columnsLabels = newColumnsLabels;
            } else {
                this.columnsLabels = newColumnsLabels[0].split("\\,");
            }
        }
        return this;
    }


}